import Vue from 'vue'
import Vuex from 'vuex'
import api from '@/api/index.js'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    tabbarActive:'',
    code: "",
    access_token: "",
    openid: "obD_t1D_-_MgWCD3T3Jtk6GPdCUw", // obD_t1IWb-PCqNTW9GoIUOCGGoog zw obD_t1D_-_MgWCD3T3Jtk6GPdCUw obD_t1DQGbgVrCFnluGvhS12uhR8,obD_t1D_-_MgWCD3T3Jtk6GPdCUw dx,obD_t1CJQMV3LhLx0psum-iUdudI qt
    // openid: "",
    appid: "",
    secret: "",
    masterColor: '#FF0000',
    isLogin: false,
    tabbar: [],
    swipeList: [],
    caseTabsList: [],
    caseList: [],
    caseListFinished: false,
    caseItem: "",
    activityItem: "",
    userInfo: '',
    activityData: {},
    activityStatus1: '',
    fansInfo: '',
    myInfo: '',
    minimum: '',
    protocolText: '',
    create_form: {
      list: [{
        type: "input",
        label: "姓名",
        options: {
          width: "100%",
          defaultValue: "",
          placeholder: "请输入姓名",
          disabled: false,
          maxLength: 11
        },
        model: "name",
        key: "name",
        rules: [{
          required: true,
          message: "必填项"
        }, {
          pattern: "[\\u4e00-\\u9fa5]",
          message: "请输入正确姓名"
        }]
      }, {
        type: "input",
        label: "联系方式",
        options: {
          width: "100%",
          defaultValue: "",
          placeholder: "请输入联系方式",
          disabled: false,
          maxLength: 11
        },
        model: "mobile",
        key: "mobile",
        rules: [{
          required: true,
          message: "必填项"
        }, {
          pattern: "^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9]|19[0|1|2|3|5|6|7|8|9])\\d{8}$",
          message: "请输入正确手机号"
        }]
      }],
      config: {
        layout: "horizontal",
        labelCol: {
          span: 4
        },
        wrapperCol: {
          span: 18
        },
        hideRequiredMark: true,
        customStyle: ""
      }
    },
	merchantItem:'',
    employee: {},
    staff_id: null,
    promoterConfig:'',
    promoterItema:'',
    p_promoter_id:'',
    Merchantvalue: ''
  },
  mutations: {
    SETMERCHANTVALUE(state, value) {
      state.Merchantvalue = value
    },
    setPromoterConfig(state,data) {
      state.promoterConfig = data;
    },
    setStaffId(state, rawData) {
      state.staff_id = rawData;
    },
    setEmployee(state, rawData) {
      state.employee = rawData;
    },
    setTabbarActive(state, rawData) {
      state.tabbarActive = rawData;
    },
    setProtocolText(state, rawData) {
      state.protocolText = rawData;
    },
    setMininum(state, rawData) {
      state.minimum = rawData;
    },
    setMyInfo(state, rawData) {
      state.myInfo = rawData;
    },
    setActivityStatus1(state, rawData) {
      state.activityStatus1 = rawData;
    },
    setActivityData(state, rawData) {
      state.activityData = rawData;
    },
    setUserInfo(state, rawData) {
      state.userInfo = rawData;
    },
    setAccessToken(state, rawData) {
      state.access_token = rawData;
    },
    setOpenid(state, rawData) {
      state.openid = rawData;
    },
    setCode(state, rawData) {
      state.code = rawData;
    },
    setActivityItem(state, rawData) {
      state.activityItem = rawData;
    },
    setCaseTabsList(state, rawData) {
      state.caseTabsList = rawData;
    },
    setCaseList(state, rawData) {
      state.caseList = rawData;
    },
    setCaseListFinished(state, b) {
      state.caseListFinished = b;
    },
    setCaseItem(state, rawData) {
      state.caseItem = rawData;
    },
    setSwipeList(state, rawData) {
      state.swipeList = rawData;
    },
    setAppid(state, rawData) {
      state.appid = rawData;
    },
    setSecret(state, rawData) {
      state.secret = rawData;
    },
    setTabbar(state, rawData) {
      state.tabbar = rawData;
    },
    setColor(state, rawData) {
      state.mainColor = rawData;
      console.log(state.mainColor)
    },
    setMasterColor(state, rawData) {
      state.masterColor = rawData;
      console.log(state.masterColor)
    },
    SET_MerchantItem(state, rawData) {
      state.merchantItem = rawData;
    },
    setPromoterItema(state,data) {
      state.promoterItema = data;
    },
    setPPromoterId(state,data) {
      state.p_promoter_id = data;
    },
  },
  actions: {
    async getMerchantValue({commit}) {
      const result = await api.getMerchantConfig()
      if(result.ret == 200) {
        commit('SETMERCHANTVALUE', result.data.value)
      }
    },
	GET_promoterItema({ commit }, params){
		return new Promise((resolve, reject) => {
		  api.PromoterItema(params).then(res => {
		    const result = res.data.data
			  if(result){
				  commit('setPromoterItema', result)
			  }
		    resolve(result)
		  }).catch(error => {
		    reject(error)
		  })
		})
	},
	GET_promoterConfig({ commit }, params){
		return new Promise((resolve, reject) => {
		  api.getConfigItemcommission(params).then(res => {
		    const result = res.data.value
			  if(result){
				  commit('setPromoterConfig', result)
			  }
		    resolve(result)
		  }).catch(error => {
		    reject(error)
		  })
		})
	},
	// 获取商户信息
	GET_MerchantItem ({ commit }, params) {
	  return new Promise((resolve, reject) => {
	    api.getMerchantItem(params).then(res => {
	      const result = res.data
		  if(result&&result.id){
			  commit('SET_MerchantItem', result)
		  }
	      resolve(result)
	    }).catch(error => {
	      reject(error)
	    })
	  })
	},
  },
  getters: {
	promoterItema(state) {
		return state.promoterItema
	},
	promoterConfig(state) {
		return state.promoterConfig
	},
    tabbarActive(state) {
      return state.tabbarActive
    },
    getActivityItem(state) {
      return state.activityItem
    },
    getOpenid(state) {
      return state.openid;
    },
    getAppid(state) {
      return state.appid;
    },
    getSecret(state) {
      return state.secret;
    },
    getMasterColor(state) {
      return state.masterColor;
    },
    getMainColor(state) {
      return state.masterColor;
    },
    getTabbar(state) {
      return state.tabbar;
    },
    getSwipeList(state) {
      return state.swipeList;
    },
    getCaseTabsList(state) {
      return state.caseTabsList;
    },
    getCaseList(state) {
      return state.caseList;
    },
    getCaseListFinished(state) {
      return state.caseListFinished;
    },
    getCaseItem(state) {
      return state.caseItem;
    }
  },
  modules: {}
})